import '../../assets/css/reset.css';
import '../../assets/font/iconfont.css';
import './main.css';

var BASE_URL = 'http://120.76.136.131:3554/madp-html-cache';

$(function () {
  $.ajax({
    type: 'POST',
    url: BASE_URL + '/api/home.do'
  }).then(function (response) {
    // loadding隐藏
    $('.icon-loadding').css({'opacity': 0, 'display': 'none'});
    // 获取轮播图数据
    var banners = response.data.banners,bannersTags = '';
    for(var i = 0; i < banners.length; i ++){
      bannersTags += '<div class="swiper-slide"><img src="' + BASE_URL + '/h5' +  banners[i].image + '" /><div>' + banners[i].title + '</div></div>';
    }
    $('.swiper-wrapper').html(bannersTags);
    new Swiper('.swiper-container', {
      pagination: '.swiper-pagination',
      autoplay: 5000,//可选选项，自动滑动
    });

    // 获取功能容器节点
    var funs = response.data.funs, funsTags = '';
    for(var i = 0; i < funs.length; i ++){
      if((i % 4) == 0){
        funsTags += '<div class="fun-icon-row">';
      }
      funsTags += '<div class="fun-icon-col">';
      funsTags += '<i class="icon iconfont ' + funs[i].icon + '"></i>';
      funsTags += '<div>' + funs[i].title + '</div>';
      funsTags += '</div>';
      if((i % 4) == 3){
        funsTags += '</div>';
      }
    }
    $('.fun-icon-container').html(funsTags);

    // 获取理财产品数据
    var prods = response.data.prods, prodsTags = '';
    for(var i = 0; i < prods.length; i ++){
      prodsTags += '<div class="prod-list-row">';
      prodsTags += '<div class="prod-list-left">';
      prodsTags += '<div>' + prods[i].prodName + '</div>';
      prodsTags += '<div>' + prods[i].prodDesc + '</div>';
      prodsTags += '</div>';
      prodsTags += '<div class="prod-list-right">';
      prodsTags += '<div>' + prods[i].income + '</div>';
      prodsTags += '<div>七年年化收益率</div>';
      prodsTags += '</div>';
      prodsTags += '</div>';
    }
    $('.prod-list-container').html(prodsTags);
  })
});
